package br.edu.unoesc.minibi.service.impl;

import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

import br.edu.unoesc.minibi.VO.AreaPlantadaVO;
import br.edu.unoesc.minibi.model.AreaPlantada;
import br.edu.unoesc.minibi.model.Cultura;
import br.edu.unoesc.minibi.service.AreaPlantadaServiceInterface;

@ApplicationScoped
@ManagedBean(name = "areaPlantadaService")
public class AreaPlantadaServiceImpl extends ServiceBaseImpl<AreaPlantada> implements AreaPlantadaServiceInterface {

	public List<AreaPlantadaVO> getAreaPlantadaGrafico(Cultura cultura) {
		String sql = "select NEW br.edu.unoesc.minibi.VO.AreaPlantadaVO(ap.cultura.nome, ap.areaEmHectares, ap.ano)"
				+ " from AreaPlantada ap where ap.cultura=:cultura order by ap.ano";

		return getEntityManager().createQuery(sql).setParameter("cultura", cultura).getResultList();
	}
}
